package com.lyw.controller;



import com.lyw.pojo.House;
import com.lyw.service.HouseService;
import com.lyw.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/house")
@CrossOrigin
public class HouseController {
    @Autowired
    private HouseService houseService;

    //查询所有
    @GetMapping("/listHouse")
    public List<House> listHouse(){
        return houseService.listHouse();
    }

    //分页模糊
    @GetMapping("/findAll")
    public PageUtil<Map<String ,Object >> findAll(
            @RequestParam(value = "name",defaultValue ="") String name,
            @RequestParam(value = "pageSize",defaultValue = "1") Integer pageSize,
            @RequestParam(value = "pageNum",defaultValue = "3") Integer pageNum
    ){
        Page<Map<String ,Object>> page = houseService.findList(name,pageSize,pageNum);
        return new PageUtil<Map<String ,Object>>(pageSize,page.getTotalElements(),page.getContent(),pageNum);
    }

    //删除
    @DeleteMapping("/delId")
    public void delId(Long id){
        houseService.delId(id);
    }

    //添加
    @PostMapping("/addHouse")
    public void addHouse(@RequestBody House house){
        houseService.addHouse(house);
    }

    //回显
    @GetMapping("/findId")
    public House findId(Long id){
        return houseService.findId(id);
    }

    //修改
    @PutMapping("/updHouse")
    public void updHouse(@RequestBody House house){
        houseService.updHouse(house);
    }

    //买房
    @GetMapping("/mai")
    public List<House> mai(){
       return houseService.mai();
    }

    //租房
    @GetMapping("/zu")
    public List<House> zu(){
        return houseService.zu();
    }

    //二手房
    @GetMapping("/two")
    public List<House> two(){
        return houseService.two();
    }

}
